
** set path
// gl path ""

** open log
cap log close
log using "$path/table8.log", replace

use "$path/foreclosures_analysis.dta", clear

** use only foreclosures in last 6 months before election

bootstrap _b, rep(1e3) seed(94305) cluster(fips) force: reghdfe pres_vs foreclosure_rate_six foreclosure_inc_six [aw=pop_y], a(fips sy) cluster(fips)
local b1 = _b[foreclosure_rate_six]
local se1 = _se[foreclosure_rate_six]
local bint1 = _b[foreclosure_inc_six]
local seint1 = _se[foreclosure_inc_six]
local n1 = e(N)
local nclust1 = e(N_clust)

bootstrap _b, rep(1e3) seed(94305) cluster(fips) force: reghdfe pres_vs foreclosure_rate_six foreclosure_inc_six [aw=pop_y], a(fips popyear) cluster(fips)
local b2 = _b[foreclosure_rate_six]
local se2 = _se[foreclosure_rate_six]
local bint2 = _b[foreclosure_inc_six]
local seint2 = _se[foreclosure_inc_six]
local n2 = e(N)
local nclust2 = e(N_clust)

bootstrap _b, rep(1e3) seed(94305) cluster(fips) force: reghdfe pres_vs foreclosure_rate_six foreclosure_inc_six [aw=pop_y], a(i.fips##c.year sy) cluster(fips)
local b3 = _b[foreclosure_rate_six]
local se3 = _se[foreclosure_rate_six]
local bint3 = _b[foreclosure_inc_six]
local seint3 = _se[foreclosure_inc_six]
local n3 = e(N)
local nclust3 = e(N_clust)

bootstrap _b, rep(1e3) seed(94305) cluster(fips) force: reghdfe pres_vs foreclosure_rate_six foreclosure_inc_six [aw=pop_y], a(i.fips##c.year popyear) cluster(fips)
local b4 = _b[foreclosure_rate_six]
local se4 = _se[foreclosure_rate_six]
local bint4 = _b[foreclosure_inc_six]
local seint4 = _se[foreclosure_inc_six]
local n4 = e(N)
local nclust4 = e(N_clust)

log close

quietly {
	cap log close
	set linesize 255
	log using "$path/foreclosure_pres_six.tex", text replace
	
	noisily dis "\begin{table}[t]"
	noisily dis "\centering"
	noisily dis "\caption{\textbf{Effects of Recent Housing Foreclosures on Presidential Elections, County Level, 2004--2016.}"
	noisily dis "\label{tab:pres_six}}"
	noisily dis "\begin{tabular}{lcccc}"
	noisily dis "\toprule \toprule"
	noisily dis " & \multicolumn{4}{c}{Dem Pres Vote Pct (0-100)}\\"
	noisily dis " & (1) & (2) & (3) & (4) \\"
	noisily dis "\midrule"
	noisily dis "Foreclosures Per 1,000 People & " %4.2f `b1' " & " %4.2f `b2' " & " %4.2f `b3' " & " %4.2f `b4'  "\\"
	noisily dis " & (" %4.2f `se1' ") & (" %4.2f `se2' ") & (" %4.2f `se3' ") & (" %4.2f `se4' ") \medskip \\"
	noisily dis "Foreclosures $ \times $ Inc Party &  " %4.2f `bint1' " & " %4.2f `bint2' " & " %4.2f `bint3' " & " %4.2f `bint4'  "\\"
	noisily dis " & (" %4.2f `seint1' ") & (" %4.2f `seint2' ") & (" %4.2f `seint3' ") & (" %4.2f `seint4' ") \medskip \\"

	noisily dis " N & " %4.0fc `n1' " & " %4.0fc `n2' " & " %4.0fc `n3' " & " %4.0fc `n4' " \\ "
	noisily dis " \# Counties & "  %4.0fc `nclust1' " & " %4.0fc `nclust2' " & " %4.0fc `nclust3' " & " %4.0fc `nclust4' " \\ "
	noisily dis "County Fixed Effects & Y & Y & Y & Y  \\"
	noisily dis "State-Year Fixed Effects & Y & N & Y & N \\"
	noisily dis "Pop Decile-Year Fixed Effects & N & Y & N & Y \\"
	noisily dis "County Linear Trends & N & N & Y & Y  \\"
	noisily dis " Population Weights & Y & Y & Y & Y \\"
	noisily dis "\bottomrule \bottomrule"
	noisily dis "\multicolumn{5}{p{.65\textwidth}}{\footnotesize Standard errors generated from 1,000 iterations of a county-level block bootstrap procedure.  "
	noisily dis "Inc Party is 1 for Dem, -1 for Rep.  Main effect for Inc Party is absorbed by fixed effects.}"
	noisily dis "\end{tabular}"
	noisily dis "\end{table}"
	
	log off
	
}
